package cn.bdqn.asecu.service;

import cn.bdqn.pojo.AttrList;
import cn.bdqn.pojo.Attributes;
import cn.bdqn.repository.Asecu_AttrListRepository;
import cn.bdqn.repository.Asecu_AttrManagementRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 属性管理业务层
 */
@Service
public class AttributeManagementService {
    @Resource
    Asecu_AttrManagementRepository asecu_attrManagementRepository;

    @Resource
    Asecu_AttrListRepository asecu_attrListRepository;

    public List<Attributes> findAll() {
        List<Attributes> list = asecu_attrManagementRepository.findAll();
        return list;
    }

    public List<AttrList> showAttrList(Integer attrId) {
        List<AttrList> attrlists = asecu_attrListRepository.findByAttrId(attrId);
        return attrlists;
    }
    @Transactional
    public boolean addAttr(Attributes attributes) {
        Attributes b = asecu_attrManagementRepository.save(attributes);

        return b!=null?true:false;
    }
    public Attributes findOne(Integer id) {
        Attributes attributes = asecu_attrManagementRepository.findById(id).get();
        return attributes;
    }
    @Transactional
    public boolean updateAttr(Attributes attributes) {
        Attributes b = asecu_attrManagementRepository.save(attributes);
        return b!=null?true:false;
    }

    @Transactional
    public void delAttr(Integer[] ids) {
        for (Integer id : ids) {
            asecu_attrManagementRepository.deleteById(id);
            asecu_attrListRepository.deleteByAttrId(id);
        }
    }
    @Transactional
    public boolean addAttrList(AttrList attrList) {
        AttrList list = asecu_attrListRepository.save(attrList);
        return list!=null?true:false;
    }

    public AttrList findOneAttrList(Integer id) {
        AttrList attrList = asecu_attrListRepository.findById(id).get();
        return attrList;
    }
    @Transactional
    public boolean updateAttrList(AttrList attrList) {
        AttrList b = asecu_attrListRepository.save(attrList);
        return b!=null?true:false;
    }
    @Transactional
    public void delListattr(Integer[] ids) {
        for (Integer id : ids) {
            asecu_attrListRepository.deleteById(id);
        }
    }
}
